#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>

int main()
{
    printf("pid : %d, ppid : %d\n",getpid(),getppid());
    pid_t id = fork();//创建子进程
    int val = 0;
    (void)id;
    if(id > 0)
    {
        while(1)
        {
            printf("我是父进程，pid = %d,ppid = %d,id = %d,val = %d\n",getpid(),getppid(),id,val);
            val += 1;
            sleep(1);
        }
    }
    else if(id == 0)
    {
        while(1)
        {
            printf("我是子进程，pid = %d,ppid = %d,id = %d,val = %d\n",getpid(),getppid(),id,val);
            val += 10;
            sleep(1);
        }
    }


    //chdir("/home/zzx/linux-code");
    //FILE* f = fopen("log.txt","w");
    //if(f == NULL)
    //{
    //    perror("fopen fail!");
    //} 
    //pid_t pid = getpid();
    //pid_t ppid = getppid();
    //while(1)
    //{
    //    printf("process's pid = %d , ppid = %d\n",pid , ppid);
    //    sleep(1);
    //}
    
    return 0;
}
